package com.webdemo11.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.webdemo11.pojo.User;
import com.webdemo11.service.UserService;

public class AddUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private UserService userService;
	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user= new User();
		String name = request.getParameter("name");
		user.setName(name);
		userService.addUser(user);
		response.sendRedirect(request.getSession().getServletContext().getContextPath()+"/queryUser");
	}
}
